<?php

/*
*
* BEGIN commentary_management_ui.php
*
*
* Dazzler Game Management Uis
* @Description: The class creates all the UIs for the commentary management
* @Authors: Salman, Wits University
* @Copyright: © Wits University 2011 - All Rights Reserved
* @License: BSD License (http://www.linfo.org/bsdlicense.html)
*
*
* BEGIN CHANGELOG
* Developers working on thee files are REQUIRED to maintain this CHANGELOG.
* Please ensure you follow the Changelog Guidelines: http://code.google.com/p/dazzler/wiki/DazzlerDevelopGuideline?ts=1315476570&updated=DazzlerDevelopGuideline
* !==================================================================================================================================================================
*
* VERSION 1.0.0
*	+ File Created, Salman, 30 September 2011
*
* ==================================================================================================================================================================!
* END CHANGELOG
*/


/*******************************************************************************************************************************************************************
*
* BEGIN Direct Call Check
*
/******************************************************************************************************************************************************************/
global $doNotCallThisScriptDirectly;
if ($doNotCallThisScriptDirectly != 1)
{
	/* Read the ini language file */
	$ini_lang_array = array();
	$clientlang = explode(",", strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
	$lang_ini_array = (file_exists("lang/" . trim($clientlang[0]) . ".ini")) ? parse_ini_file("lang/" . trim($clientlang[0]) . ".ini", true) : parse_ini_file("lang/en.ini", true);
	die ($lang_ini_array['ERRORS']['doNotCallThisScriptDirectly']);
}
/*******************************************************************************************************************************************************************
*
* END Direct Call Check
*
/******************************************************************************************************************************************************************/

class commentary_management_ui extends baseClass
{

    private $htmlelementsbuilder;
    private $gameID=null;

    private $parsesiteconfig;

    public function  __construct($gameID)
    {
    $this->htmlelementsbuilder = new htmlelementsbuilder();
    $this->parsesiteconfig = new parsesiteconfig();
    parent::parseLanguageErrorLogFile();
    if (isset($gameID))
    {
        $this->gameID = $gameID;
    }
    
    }


    private function buildBallTrajectoryInsertForm()
    {
        $canvascreator = new canvascreator(800, 800);
        return $canvascreator->getCanvas();
    }

    private function buildInsertBallCommetaryForm()
    {

                $UserLogic = new UserLogic();
                if($UserLogic->isUserCommentator())
                {
                  $commentatorId = $UserLogic->getCommentatorId();
                }
                else
                {
                    return "You are not a commentator. You have entered this page illegally.";
                }

        $commentatorIDHInput = new htmlcodemaker('input');
        $commentatorIDHInput->set(array('type'=>'hidden','name'=>'commentatorID','value'=>$commentatorId));
        $isFinalisedInput = new htmlcodemaker('input');
        
        
        $StatsAdmin = new StatsAdmin();
        if ($StatsAdmin->isGameFinished($this->gameID))
        {
            $isFinalisedInput->set(array('type'=>'hidden','name'=>'isGameFinished','value'=>'1'));
            return $isFinalisedInput->output().$this->showFinalResultCommentaryForm();
        }
        else
        {
           $isFinalisedInput->set(array('type'=>'hidden','name'=>'isGameFinished','value'=>'0'));
        }
        $battingPairArray = array();
        $battingPairArray = $StatsAdmin->getBattingPair($this->gameID);
        $bowlersArray = array();
        $bowlersArray = $StatsAdmin->getBowlers($this->gameID);
         asort($bowlersArray);
         $fieldingTeamArray = array();
        $fieldingTeamArray = $StatsAdmin->getPlayersOfBowlingTeam($this->gameID);


        $teamInformationArray = $StatsAdmin->getBattingAndBowlingTeams($this->gameID);
        $parseSiteConfig = new parsesiteconfig();
        $rootpath = $parseSiteConfig->getRootPath();
        $loadType = $parseSiteConfig->getLoadType();
        $battingTeamShortName = strtolower($teamInformationArray['batting']['TEAM_POOL_SNAME']);
        $bowlingTeamShortName = strtolower($teamInformationArray['bowling']['TEAM_POOL_SNAME']);
        $battingTeamIcon = "$rootpath/themes/$loadType/custom/images/logos/".$battingTeamShortName."_logo.png";
        $bowlingTeamIcon = "$rootpath/themes/$loadType/custom/images/logos/".$bowlingTeamShortName."_logo.png";

        $battingTeamLogo = new htmlcodemaker('span');
        $battingTeamLogo->set(array('class'=>'logo','style'=>'float:left; margin:0px 7px 0px 7px;','text'=>"<img name=$battingTeamShortName src=$battingTeamIcon alt=$battingTeamShortName height='33' />"));

        $bowlingTeamLogo = new htmlcodemaker('span');
        $bowlingTeamLogo->set(array('class'=>'logo','style'=>'float:left; margin:0px 7px 0px 7px;','text'=>"<img name=$bowlingTeamShortName src=$bowlingTeamIcon alt='$bowlingTeamShortName' height='33' />"));


        $commentaryForm = null;
        $commentaryForm .= $isFinalisedInput->output().$commentatorIDHInput->output();
        $commentaryForm .= "<div id='commentarytabs'>";
        $commentaryForm .= '	<ul>
		<li><a href="#ballComentary">Ball Commentary</a></li>
		<li><a href="#ballTrajectory">Ball Trajectory</a></li>

	</ul>';
        $commentaryForm .= '<div id="ballComentary">';
        $commentaryForm .= '	<style>
        #battingStatContainer, #bowlingStatContainer, #dismissalStatContainer {  width:97%; border:1px solid #CCCCCC;padding:10px 10px 10px 10px; margin:10px 10px 10px 10px;}
	</style>';
    

        $commentaryForm .= "  <div style =' border: 1px solid transparent; padding: 7px' class='responseDiv'> </div>

        <div style =' border: 1px solid transparent; padding: 7px' class='errorMessageDiv'> </div>";
        $commentaryForm .= "  <div style =' border: 1px solid transparent; padding: 0px' class='loadingScreen'> </div>";
        $commentaryForm .= "<div class='ballByBallStatsCommentaryContainer'>";
        $commentaryForm .= "<div id='battingStatContainer' class='teamsSelectContainers ui-corner-all'>";
        $commentaryForm .= $battingTeamLogo->output()."<h2>Batting</h2>";
        foreach ($battingPairArray as $batterIndex => $batsman) {
           $batsmanID = $batsman['PLAYER_ID'];
           $firstName =$batsman['PLAYER_POOL_FNAME'];
           $lastName =$batsman['PLAYER_POOL_LNAME'];
           $this->htmlelementsbuilder->addOption($batsmanID,$firstName." ".$lastName);
           if ($batterIndex == 0)
           {
             $this->htmlelementsbuilder->setSelected($batsmanID);
           }

        }
        $commentaryForm .= $this->htmlelementsbuilder->buildRadioButton("batsmanFacing", "Select batsman on strike:", "top")."<br>";
                for ($i=0; $i<=7;$i++)
        {
            $this->htmlelementsbuilder->addOption("$i","$i");
        }
        $this->htmlelementsbuilder->setSelected("1");
        $commentaryForm .= $this->htmlelementsbuilder->buildRadioButton("runsScored", "Select how many runs made:", "top")."<br>";
        $this->htmlelementsbuilder->addOption("none","none");
        $this->htmlelementsbuilder->addOption("leave","leave");
        $this->htmlelementsbuilder->addOption("block","block");
        $this->htmlelementsbuilder->addOption("forward&nbsp;defensive","forward defensive");
        $this->htmlelementsbuilder->addOption("backward&nbsp;defensive","backward defensive");
        $this->htmlelementsbuilder->addOption("hook","hook");
        $this->htmlelementsbuilder->addOption("pull","pull");
        $this->htmlelementsbuilder->addOption("leg&nbsp;glance","leg glance");
        $this->htmlelementsbuilder->addOption("straight&nbsp;drive","straight drive");
        $this->htmlelementsbuilder->addOption("on&nbsp;drive","on drive");
        $this->htmlelementsbuilder->addOption("off&nbsp;drive","off drive");
        $this->htmlelementsbuilder->addOption("cover&nbsp;drive","cover drive");
        $this->htmlelementsbuilder->addOption("square&nbsp;drive","square drive");
        $this->htmlelementsbuilder->addOption("square&nbsp;cut","square cut");
        $this->htmlelementsbuilder->addOption("cut","cut");
        $this->htmlelementsbuilder->addOption("late&nbsp;cut","late cut");
        $this->htmlelementsbuilder->addOption("sweep","sweep");
        $this->htmlelementsbuilder->addOption("reverse&nbsp;sweep","reverse sweep");
        $this->htmlelementsbuilder->addOption("cow&nbsp;shot","cow shot");
        $this->htmlelementsbuilder->addOption("slog","slog");
        $this->htmlelementsbuilder->addOption("slog&nbsp;sweep","slog sweep");
        $this->htmlelementsbuilder->addOption("scoop","scoop");
        $this->htmlelementsbuilder->addOption("other","other");
        $this->htmlelementsbuilder->setSelected('none');
        
        $commentaryForm .= $this->htmlelementsbuilder->buildRadioButton("shotType", "Select batsman shot:", "top");
        $commentaryForm .= "<div id='customShotTypeContainer'>";
        $commentaryForm .= $this->htmlelementsbuilder->buildTextInput('customShotType', "", 'customShotType', TRUE, "Insert Custom Shot Type:", 'top') . "<br>";
        $commentaryForm .= "</div>";
        $commentaryForm .= "</div>";
        $commentaryForm .= "<div id='bowlingStatContainer' class='teamsSelectContainers ui-corner-all'>";
        $commentaryForm .= $bowlingTeamLogo->output()."<h2>Bowling</h2>";
        
        $commentaryForm .= "<div id='bowlerTypeSelectorContainer'>";
        $bowlingTypesArray =array();

        foreach ($bowlersArray as $key => $bowlers) {
            
            $bowlingStyle =  $bowlers['PLAYER_POOL_BOWLSTYL'];
          $bowlingTypesArray[]=preg_replace("/[^A-Za-z0-9]/","&nbsp;",$bowlingStyle);
            $this->htmlelementsbuilder->addOption(preg_replace("/[^A-Za-z0-9]/","&nbsp;",$bowlingStyle),$bowlers['PLAYER_POOL_BOWLSTYL']);
            if ($key == '0')
            {
                $this->htmlelementsbuilder->setSelected(preg_replace("/[^A-Za-z0-9]/","&nbsp;",$bowlingStyle));
            }
        }
        
        $commentaryForm .= $this->htmlelementsbuilder->buildRadioButton("bowlerTypeSelector", "Select bowler bowling:", "top");
        $commentaryForm .= "</div>";
        $bowlingTypesArray = array_unique($bowlingTypesArray);
        foreach ($bowlingTypesArray as $key => $bowlingTypes) {
       //echo $bowlingTypes;
            $commentaryForm .= "<div id='$bowlingTypes' class='bowlingPlayerTypes'>";
        foreach ($bowlersArray as $bowlers) {
            $bowlingStyle =  $bowlers['PLAYER_POOL_BOWLSTYL'];
            if (preg_replace("/[^A-Za-z0-9]/","&nbsp;",$bowlingStyle) == $bowlingTypes)
            {
                $this->htmlelementsbuilder->addOption($bowlers['PLAYER_ID'],$bowlers['PLAYER_POOL_FNAME']." ".$bowlers['PLAYER_POOL_LNAME']);
                if ($key == '0')
                {
                  $this->htmlelementsbuilder->setSelected($bowlers['PLAYER_ID']);
                }

                
            }

        }
            if (!empty($this->htmlelementsbuilder->options))
            {
                $commentaryForm .=  $this->htmlelementsbuilder->buildRadioButton("bowlerAttacking", "", "");
            }

            $commentaryForm .= "</div>";
       
        }

        
        $this->htmlelementsbuilder->addOption("legspin","leg spin");
        $this->htmlelementsbuilder->addOption("offspin","off spin");
        $this->htmlelementsbuilder->addOption("fastbowling","fast bowling");
        $this->htmlelementsbuilder->addOption("other","other");
        $this->htmlelementsbuilder->setSelected('legspin');
        $commentaryForm .= "<br>".$this->htmlelementsbuilder->buildRadioButton("ballSelectorType", "Select delivery type:", "top");
        $commentaryForm .= "<div id='legSpinDeliveryTypeContainer'>";
        $this->htmlelementsbuilder->addOption("leg&nbsp;break","leg break");
        $this->htmlelementsbuilder->addOption("googly","googly");
        $this->htmlelementsbuilder->addOption("topspinner&nbsp;legspin","topspinner (leg spin)");
        $this->htmlelementsbuilder->addOption("flipper","flipper");
        $this->htmlelementsbuilder->addOption("slider","slider");
        $this->htmlelementsbuilder->addOption("flicker&nbsp;ball","flicker ball");
        $this->htmlelementsbuilder->setSelected('leg&nbsp;break');
        
        $commentaryForm .= $this->htmlelementsbuilder->buildRadioButton("deliveryType", null, null);
        $commentaryForm .= "</div>";
        $commentaryForm .= "<div id='offSpinDeliveryTypeContainer'>";
        $this->htmlelementsbuilder->addOption("off&nbsp;break","off break");
        $this->htmlelementsbuilder->addOption("doosra","doosra");
        $this->htmlelementsbuilder->addOption("arm&nbsp;ball","arm ball");
        $this->htmlelementsbuilder->addOption("topspinner&nbsp;offspin","topspinner (off spin)");
        $this->htmlelementsbuilder->addOption("carrom&nbsp;ball","carrom ball");
        $this->htmlelementsbuilder->addOption("teesra","teesra");
        $commentaryForm .= $this->htmlelementsbuilder->buildRadioButton("deliveryType", null, null);
        $commentaryForm .= "</div>";
       
        $commentaryForm .= "<div id='fastBowlingDeliveryTypeContainer'>";
        $this->htmlelementsbuilder->addOption("bouncer","bouncer");
        $this->htmlelementsbuilder->addOption("inswinger","inswinger");
        $this->htmlelementsbuilder->addOption("reverse&nbsp;swing","reverse swing");
        $this->htmlelementsbuilder->addOption("leg&nbsp;cutter","leg cutter");
        $this->htmlelementsbuilder->addOption("off&nbsp;cutter","off cutter");
        $this->htmlelementsbuilder->addOption("outswinger","outswinger");
        $this->htmlelementsbuilder->addOption("yorker","yorker");
        $this->htmlelementsbuilder->addOption("illegal&nbsp;beamer","beamer (illegal)");

        $commentaryForm .= $this->htmlelementsbuilder->buildRadioButton("deliveryType", null, null);
        $commentaryForm .= "</div>";
        $commentaryForm .= "<div id='customDeliveryTypeContainer'>";
        $commentaryForm .= $this->htmlelementsbuilder->buildTextInput('customDeliveryType', "", 'customDeliveryType', TRUE, "Insert Custom Ball Delivery Type:", 'top') . "<br>";
        $commentaryForm .= "</div>";
        $this->htmlelementsbuilder->addOption("none","none");
        $this->htmlelementsbuilder->addOption("dead&nbsp;ball","dead ball");
        $this->htmlelementsbuilder->addOption("wide","wide");
        $this->htmlelementsbuilder->addOption("leg&nbsp;bye","leg bye");
        $this->htmlelementsbuilder->addOption("bye","bye");
        $this->htmlelementsbuilder->addOption("no&nbsp;ball&nbsp;overstep","no ball (over step)");
        $this->htmlelementsbuilder->addOption("no&nbsp;ball&nbsp;too&nbsp;high","no ball (too high)");
        $this->htmlelementsbuilder->addOption("other","other");
        $this->htmlelementsbuilder->setSelected('none');
        $commentaryForm .= "<br>".$this->htmlelementsbuilder->buildRadioButton("extraType", "Select Extras:", "top");
        $commentaryForm .= "<div id='customExtraTypeContainer'>";
        $commentaryForm .= $this->htmlelementsbuilder->buildTextInput('customExtraType', "", 'customExtraType', TRUE, "Insert Custom Extra Type:", 'top') . "<br>";
        $commentaryForm .= "</div>";
         $commentaryForm .='<p>
	<label for="ballSpeed">Delivery Speed:</label><br>
	<input type="text" id="ballSpeed" style="border:0; color:#f6931f; font-weight:bold;" />
        <input type="text" id="ballSpeed-mph" style="border:0; color:#f6931f; font-weight:bold;" />
        </p>
        <div id="slider-ballSpeed"></div>';

        $commentaryForm .= "</div>";
                $commentaryForm .= "<div id='dismissalStatContainer' class='teamsSelectContainers ui-corner-all'>";
        $commentaryForm .= "<h2>Dismissal</h2>";
        $commentaryForm .= $this->htmlelementsbuilder->buildCheckBox("isDismissed", "Player has been dismissed");
        $commentaryForm .= "<div id='dismissalDetailsContainer'>";
        $this->htmlelementsbuilder->addOption("bowled","bowled");
        $this->htmlelementsbuilder->addOption("caught","caught");
        $this->htmlelementsbuilder->addOption("LBW","LBW");
        $this->htmlelementsbuilder->addOption("bye","bye");
        $this->htmlelementsbuilder->addOption("run&nbsp;out","run out");
        $this->htmlelementsbuilder->addOption("stumped","stumped");
        $this->htmlelementsbuilder->addOption("other","other");
        $this->htmlelementsbuilder->setSelected('bowled');
        $commentaryForm .= "<br>".$this->htmlelementsbuilder->buildRadioButton("dismissalType", "Select Dismissal Type:", "top");
                $commentaryForm .= "<div id='customDismissalTypeContainer'>";
        $commentaryForm .= $this->htmlelementsbuilder->buildTextInput('customDismissalType', "", 'customDismissalType', TRUE, "Insert Custom Dismissal Type:", 'top') . "<br>";
        $commentaryForm .= "</div>";
        foreach ($fieldingTeamArray as $key => $fielders) {
             $this->htmlelementsbuilder->addOption(preg_replace("/[^A-Za-z0-9]/","",$fielders['PLAYER_POOL_FNAME']." ".$fielders['PLAYER_POOL_LNAME']),$fielders['PLAYER_POOL_FNAME']." ".$fielders['PLAYER_POOL_LNAME']);
             if($key == '0')
             {
                 $this->htmlelementsbuilder->setSelected(preg_replace("/[^A-Za-z0-9]/","",$fielders['PLAYER_POOL_FNAME']." ".$fielders['PLAYER_POOL_LNAME']));
             }

        }
        $commentaryForm .= "<br>".$this->htmlelementsbuilder->buildRadioButton("dismissalFeilder", "Select Player that dismissed the batsman:", "top");

        $commentaryForm .= "</div>";



        $commentaryForm .= "</div>";
                                $commentaryForm .= "<div id='dismissalStatContainer' class='teamsSelectContainers ui-corner-all'>";
        $commentaryForm .= "<h2>Commentary</h2>";
        $commentaryForm .= $this->htmlelementsbuilder->buildTextArea("ballCommentary", "", "ballCommmentary", TRUE, "Insert commentary for ball:", "top", "5", "63");
        $commentaryForm .= "</div>";
        $commentaryForm .= "</div>";
        $commentaryForm .= "</div>";
        $commentaryForm .= '	<div id="ballTrajectory">';
        $commentaryForm .= "<div class='ballTrajectoryResponseDiv'></div>";
        $commentaryForm .= $this->buildBallTrajectoryToolBar();
 $commentaryForm .= $this->buildBallTrajectoryInsertForm();
//$commentaryForm .= '<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>';

$commentaryForm .= "</div>";



        $commentaryForm .= "</div>";
        return $commentaryForm;
    }


        /*!
     * \brief This member function sets up the editor toolbar that gets displayed
     * above the html5 canvas.
     * \brief Some text, the form element inserter drop down and two buttons delete and
     * rearrange form elements get concatenated into a large span.
     * \return A constructed toolbar that gets displayed on top of the ball trajectory canvas
     */
    private function buildBallTrajectoryToolBar() {
        $trajectoryOptionDropDown = new htmlcodemaker('dropdown');
        $trajectoryOptionDropDown->set(array('name'=>'trajectoryTypeSelector','id'=>'trajectoryTypeSelector'));
        $trajectoryOptionDropDown->setOption("line", "Straight Line");
        $trajectoryOptionDropDown->setOption("parabola", "Parabolic");
        $trajectoryOptionDropDown->setOption("besselic", "Besselic");
        $trajectoryOptionDropDown->setOption("pencil", "Custom");
        $trajectoryOptionDropDown->setDefaultOptionWithValue("straightline");

        $toolBarUnderConstrunction = '<div id="toolbar" class="ui-state-default ui-corner-all"style="border:1px solid #CCCCCC;padding:5px 5px 5px 5px; margin: 5px 5px 5px 5px; font-size:80%">';
        $toolBarUnderConstrunction .= "<sup>Ball Trajectory Toolbar</sup>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        $toolBarUnderConstrunction .= "Insert A:   ";
        $toolBarUnderConstrunction .=$trajectoryOptionDropDown->output() . "
&nbsp;Ball Trajectory&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        $toolBarUnderConstrunction .= "<button id='clearCanvasButton'>Clear Ball Trajectory</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        $toolBarUnderConstrunction .= "Show Fielding Positions : <input type='checkbox' id='highlightCricketPitchAreasButton' /><label for='highlightCricketPitchAreasButton'>Toggle</label>";
                 $this->htmlelementsbuilder->addOption("Left", "Left Handed");
       $this->htmlelementsbuilder->addOption("Right", "Right Handed");
        $this->htmlelementsbuilder->setSelected("Right");
       $toolBarUnderConstrunction .= "<div id='batsmanTypeContainer' align='right'>".$this->htmlelementsbuilder->buildRadioButton("batsmanType", "Select Batsman Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", "left")."</div>";
        $toolBarUnderConstrunction .= '</div>';
        return $toolBarUnderConstrunction;
    }

    private function buildBallStatsIndicator()
    {

        $StatsAdmin = new StatsAdmin();
        $scoreArray = $StatsAdmin->getCurrentScore($this->gameID);
        $teamsArray = $StatsAdmin->getBattingAndBowlingTeams($this->gameID);
        $battingTeamShortName = strtolower($teamsArray['batting']['TEAM_POOL_SNAME']);
        $bowlingTeamShortName = strtolower($teamsArray['bowling']['TEAM_POOL_SNAME']);

        //$teamsArray['batting']['TEAM_POOL_NAME'];

        $ballStatsContent ="<div class='panel'>";
//	<h3>".$teamsArray['batting']['TEAM_POOL_NAME']." Vs. ".$teamsArray['bowling']['TEAM_POOL_NAME']."</h3>";

         $ballStatsContent .= "<div style='width:320px; height:125px;'>";
        $ballStatsContent .= "<div class ='teamLogo ".$battingTeamShortName."_home_logo'></div><p align='center' style='float:left; padding:30px 1px 0px 1px; width:120px;'><strong>". $teamsArray['batting']['TEAM_POOL_NAME'] ." Vs.";
        $ballStatsContent .= $teamsArray['bowling']['TEAM_POOL_NAME']." </strong></p><div class ='teamLogo ".$bowlingTeamShortName."_home_logo'></div>";
        $ballStatsContent .= "</div>";

        if ($scoreArray['Innings'] == '1')
        {
            $ballStatsContent .= "<p><b>".$teamsArray['batting']['TEAM_POOL_NAME']." first innings.</b></p>";
            $ballStatsContent .= "<p>".$scoreArray['firstInnings']['runs']."/".$scoreArray['firstInnings']['wickets']."&nbsp;&nbsp;&nbsp;&nbsp;".$scoreArray['firstInnings']['overs'] ." overs</p>";
            $ballStatsContent .= "<p><b>".$teamsArray['bowling']['TEAM_POOL_NAME']." will bat in the second innings.</b></p>";

        }
        else
        {
            $wicketsRemaining = 10 - $scoreArray['firstInnings']['wickets'];
            $ballStatsContent .= "<p><b>".$teamsArray['bowling']['TEAM_POOL_NAME']." made ".$scoreArray['firstInnings']['runs']." after ".$scoreArray['firstInnings']['overs']." overs with ".$wicketsRemaining." wickets remaining.</b></p>";
            $ballStatsContent .= "<p><b>".$teamsArray['batting']['TEAM_POOL_NAME']." second innings.</b></p>";
            $ballStatsContent .= "<p>".$scoreArray['secondInnings']['runs']."/".$scoreArray['secondInnings']['wickets']."&nbsp;&nbsp;&nbsp;&nbsp;".$scoreArray['secondInnings']['overs'] ." overs</p>";

        }
        $ballStatsContent .= "</div>";
                $indicatorTrigger = new htmlcodemaker('a');
        $indicatorTrigger->set(array('class'=>'trigger','href'=>'#','text'=>'Stats'));
        $ballStatsContent .= $indicatorTrigger->output();
        return $ballStatsContent;
    }

    public function showBallStatsIndicator()
    {
        return $this->buildBallStatsIndicator();
    }


    public function showInsertBallCommentaryForm()
    {
        return $this->buildInsertBallCommetaryForm();
    }



    private function buildFinalResultCommentaryForm()
    {
                $finalResult = "  <div style =' border: 1px solid transparent; padding: 7px' class='responseDiv'> </div>

        <div style =' border: 1px solid transparent; padding: 7px' class='errorMessageDiv'> </div>";
        $finalResult .= "<h2>The Match has ended</h2>";
        $finalResult .= $this->htmlelementsbuilder->buildTextArea("finalResultCommentary", NULL, "", TRUE, "Insert Final Result Commentary", "top", '5', '50');
        return $finalResult;
    }


    private function buildGameManagementTopButtons()
    {
       // $topButtons = "<div>";
        $topButtons = "<h2>Games</h2>";
        $topButtons .= $this->htmlelementsbuilder->buildButton("addGame", "Create New Game", "gameManagementButtons");
        $topButtons .= $this->htmlelementsbuilder->buildButton("updateGameDetails", "Update Active Game Details", "gameManagementButtons");
        $topButtons .= $this->htmlelementsbuilder->buildButton("deleteGames", "Remove Inactive Games", "gameManagementButtons");
       // $topButtons .= "</div>";
        return $topButtons;
    }

    public function showFinalResultCommentaryForm()
    {
        return $this->buildFinalResultCommentaryForm();
    }

    public function showInsertPlayerIntoForm($gameID)
    {
        return $this->buildInsertPlayerIntoForm($gameID);
    }

    public function showGameTossForm($homeTeamID,$homeTeamName,$awayTeamID,$awayTeamName)
    {
        return $this->buildGameTossForm($homeTeamID, $homeTeamName, $awayTeamID, $awayTeamName);
    }


    public function showGameTopPage()
    {
        return $this->buildGameManagementTopButtons();
    }

//     public function showAddGameForm()
//    {
//        return $this->buildAddGameForm();
//    }




}